let app = getApp();
// 引入文件/数据（引入前需导出module.exports）
var classicData = require("../data/classicdata.js" );
Page({
  data: {
    inputValue: '',
    // tiangou:['世事如棋，一步三算']
    // 初始化数据为空：tiangou
    tiangou:[],
   //添狗语录：在https无法使用的时候调用静态的classicdata.js数据
    yuju:[],
    honor:[]
   
  },
  onLoad: function() {
    var that = this;
    // console.log(classicData);
    // console.log(classicData.classicData);
    // 获取数组长度
    var len=classicData.classicData.length;
    // console.log(len);
    // 随机获取数组的某一个id
    var lens=(Math.floor(Math.random()*len));
    // console.log(lens);
    //添狗语录：在https无法使用的时候调用静态的classicdata.js数据
    that.setData({
      yuju:classicData.classicData[lens]['yuju']
    });
   
    wx.request({
      method: "GET",
      url: "https://api.xingzhige.com/API/twqh/api.php",
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        var tiangou=res.data;
        // console.log(res.data);
        // var str1 = tiangou.replace(' ', '\n');
        // var arr=tiangou.split("↵");
        that.setData({
          tiangou:tiangou
        });
        console.log('<舔狗语录>'+tiangou);
      }
    })
    wx.request({
      method: "GET",
      url: "http://www.dashige.xyz/API/wzyy/api.php",
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        var honor=res.data;
        that.setData({
          honor:honor
        });
        console.log('<王者语录>'+honor);
      }
    })
  },
  formSubmit: function(e) {
    console.log(e.detail.value)
    console.log(e.detail.value.username)
    console.log(e.detail.value.tel)
    console.log(e.detail.value.idcard)
    console.log(e.detail.value.rank)
    var that = this;
    var username = e.detail.value.username;
    var tel = e.detail.value.tel;
    var idcard = e.detail.value.idcard;
    var rank = e.detail.value.rank;
    if (!(idcard.length === 15 || idcard.length === 18)) {
      wx.showToast({
        title: '请输入15或18位数身份证号码',
        duration: 2000
      })
    } else {
      wx.request({
        method: "POST",
        url: "",
        data: {
          'username': username,
          'tel': tel,
          'idcard': idcard,
          'rank': rank
        },
        header: {
          'content-type': 'application/json'
        },
        success: function(res) {
          wx.showToast({
            title: '保存成功',
            duration: 2000
          })
        }
      })

    }

  }


})